<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: magic_anonymous.php 6757 2010-03-25 09:01:29Z cnteacher $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

if($idtype == 'uid') {
	$query = DB::query('SELECT * FROM '.DB::table('home_visitor')." WHERE uid = '$id' AND vuid = '$_G[uid]'");
	$value = DB::fetch($query);
	if(empty($value)) {
		showmessage('magicuse_bad_object');
	} elseif($value['vusername'] == '') {
		showmessage('magicuse_object_once_limit');
	}
} elseif($idtype == 'cid') {
	$query = DB::query('SELECT * FROM '.DB::table('home_comment')." WHERE cid = '$id' AND authorid = '$_G[uid]'");
	$value = DB::fetch($query);
	if(empty($value)) {
		showmessage('magicuse_bad_object');
	} elseif($value['author'] == '') {
		showmessage('magicuse_object_once_limit');
	}
} else {
	$query = DB::query('SELECT * FROM '.DB::table('home_clickuser')." WHERE id = '$id' AND idtype = '$idtype' AND uid = '$_G[uid]'");
	$value = DB::fetch($query);
	if(empty($value)) {
		showmessage('magicuse_bad_object');
	} elseif($value['username'] == '') {
		showmessage('magicuse_object_once_limit');
	}
}

if(submitcheck("usesubmit")) {

	if($idtype == 'uid') {
		dsetcookie('anonymous_visit_'.$_G['uid'].'_'.$id, '1');
		DB::update('home_visitor', array('vusername'=>''), array('uid'=>$id, 'vuid'=>$_G['uid']));
	} elseif($idtype == 'cid') {
		DB::update('home_comment', array('author'=>''), array('cid'=>$id, 'authorid'=>$_G['uid']));
	} else {
		DB::update('home_clickuser', array('username'=>''), array('id'=>$id, 'idtype'=>$idtype, 'uid'=>$_G['uid']));
	}

	magic_use($mid, array('id'=>$id, 'idtype'=>$idtype), true);
	showmessage('magicuse_success', dreferer());
}

?>